package malus.shaofeng.com.beiwomusic.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.List;

import malus.shaofeng.com.beiwomusic.R;
import malus.shaofeng.com.beiwomusic.model.HotPost;

/**
 * 参与的话题
 */
public class PartTopicAdapter extends BaseAdapter{

    private final Context context;
    private final List<HotPost> data;

    public PartTopicAdapter(Context context,List<HotPost> data){
        if(context !=null){
            this.context = context;
            this.data = data;
        }else{
            throw new IllegalArgumentException("context must not null.");
        }
    }
    @Override
    public int getCount() {
        if(data!=null){
            return data.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if(data!=null){
            return data.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        if(convertView!=null){
            view=convertView;
        }else{
            view= LayoutInflater.from(context).inflate(R.layout.item_mine_part_topic_list,parent,false);
        }
        ViewHolder holder = (ViewHolder) view.getTag();
        if(holder==null){
            holder=new ViewHolder();
            holder.title=(TextView)view.findViewById(R.id.mine_part_title);
            holder.reply=(TextView)view.findViewById(R.id.mine_part_reply);
            view.setTag(holder);
        }
        HotPost hotPost = data.get(position);
        holder.title.setText(hotPost.getTitle());
        holder.reply.setText(hotPost.getReplies()+"回复");
       if(position%2==0){
            view.setBackgroundColor(Color.parseColor("#f0f0f0"));
       }else{
           view.setBackgroundColor(Color.parseColor("#ffffff"));
       }
        return view;
    }
    private class ViewHolder{
        TextView title;
        TextView reply;
    }

}
